package com.smartguard.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.smartguard.bean.Device;
import com.smartguard.bean.User;
import com.smartguard.bean.Video;
import com.smartguard.common.Const;
import com.smartguard.service.VideoService;
import com.smartguard.util.JSONUtil;

public class VideoAction extends BaseAction {
	
	private VideoService videoService;
	
	public VideoAction(){
		this.videoService = new VideoService();
	}
	
	public void getAllVideoList() throws IOException{
		User user= (User) this.getSession().get(Const.SESSION_USER);
		PrintWriter out = this.getWriter();
		
		if(user == null){
			JSONObject json = JSONUtil.newErrMsgJSONObject("未登录");
			out.write(json.toJSONString());
			System.out.println("test get all devicelist" + json.toJSONString());
		}
		else{
			List<Video> videoList = this.videoService.findVideosByUsername(user.getUsername());
			JSONArray jsonArray = JSONUtil.listToJSONArray(videoList);
			JSONObject json = JSONUtil.newSuccessJSONObject();
			json.put("videoList", jsonArray);
			out.write(json.toJSONString());
			System.out.println("test get all videoList" + json.toJSONString());
		}
		out.flush();
		out.close();
	}

}
